var map,mposctl,vectors, geojson,markers,selectControl;
var selectedFeature;
//Init
map = new OpenLayers.Map('ground');
layer = new OpenLayers.Layer.Image(
    "ground",
    "ground.jpg",
    new OpenLayers.Bounds(-1227,-369.5,1227,369.5),
    new OpenLayers.Size(2454,739)
);
map.addLayer(layer);
map.zoomToMaxExtent();
var featurecollection = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_92",
            "properties": {
                "name": "Canteen",
                "description": "food and drinks for students"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -1217.0205078125,
                            329.4892578125
                        ],
                        [
                            -939.0205078125,
                            329.4892578125
                        ],
                        [
                            -937.0205078125,
                            -111.5107421875
                        ],
                        [
                            -1213.0205078125,
                            -111.5107421875
                        ],
                        [
                            -1217.0205078125,
                            329.4892578125
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_114",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -815.0205078125,
                            326.4892578125
                        ],
                        [
                            -699.0205078125,
                            328.4892578125
                        ],
                        [
                            -697.0205078125,
                            136.4892578125
                        ],
                        [
                            -816.0205078125,
                            135.4892578125
                        ],
                        [
                            -815.0205078125,
                            326.4892578125
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_136",
            "properties": {
                "name": "Elevator_1",
                "description": "Ground elevator"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -819.0205078125,
                            8.4892578125
                        ],
                        [
                            -678.0205078125,
                            9.4892578125
                        ],
                        [
                            -679.0205078125,
                            -110.5107421875
                        ],
                        [
                            -821.0205078125,
                            -110.5107421875
                        ],
                        [
                            -819.0205078125,
                            8.4892578125
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_162",
            "properties": {
                "name": "Library",
                "description": "supplying reference books to students for studying and research"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -694.0205078125,
                            328.4892578125
                        ],
                        [
                            41.9794921875,
                            328.4892578125
                        ],
                        [
                            44.9794921875,
                            137.4892578125
                        ],
                        [
                            -694.0205078125,
                            136.4892578125
                        ],
                        [
                            -694.0205078125,
                            328.4892578125
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_186",
            "properties": {
                "name": "A.103",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            48.9794921875,
                            328.4892578125
                        ],
                        [
                            408.9794921875,
                            328.4892578125
                        ],
                        [
                            410.9794921875,
                            136.4892578125
                        ],
                        [
                            49.9794921875,
                            136.4892578125
                        ],
                        [
                            48.9794921875,
                            328.4892578125
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_208",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            415.9794921875,
                            329.4892578125
                        ],
                        [
                            539.9794921875,
                            327.4892578125
                        ],
                        [
                            539.9794921875,
                            135.4892578125
                        ],
                        [
                            417.9794921875,
                            133.4892578125
                        ],
                        [
                            415.9794921875,
                            329.4892578125
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_234",
            "properties": {
                "name": "A.105",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            699.9794921875,
                            287.4892578125
                        ],
                        [
                            949.9794921875,
                            287.4892578125
                        ],
                        [
                            951.9794921875,
                            -104.5107421875
                        ],
                        [
                            697.9794921875,
                            -107.5107421875
                        ],
                        [
                            699.9794921875,
                            287.4892578125
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_258",
            "properties": {
                "name": "Elevator_1",
                "description": "Ground elevator"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            393.9794921875,
                            10.4892578125
                        ],
                        [
                            538.9794921875,
                            10.4892578125
                        ],
                        [
                            537.9794921875,
                            -105.5107421875
                        ],
                        [
                            392.9794921875,
                            -106.5107421875
                        ],
                        [
                            393.9794921875,
                            10.4892578125
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_280",
            "properties": {
                "name": "Stair_1",
                "description": "Ground stair"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            536.9794921875,
                            -116.5107421875
                        ],
                        [
                            617.9794921875,
                            -115.5107421875
                        ],
                        [
                            616.9794921875,
                            -188.5107421875
                        ],
                        [
                            538.9794921875,
                            -187.5107421875
                        ],
                        [
                            536.9794921875,
                            -116.5107421875
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_304",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            203.9794921875,
                            10.4892578125
                        ],
                        [
                            387.9794921875,
                            10.4892578125
                        ],
                        [
                            388.9794921875,
                            -108.5107421875
                        ],
                        [
                            204.9794921875,
                            -109.5107421875
                        ],
                        [
                            203.9794921875,
                            10.4892578125
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_326",
            "properties": {
                "name": "Photocopy room",
                "description": "photocopy services"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -24.0205078125,
                            8.4892578125
                        ],
                        [
                            200.9794921875,
                            9.4892578125
                        ],
                        [
                            200.9794921875,
                            -106.5107421875
                        ],
                        [
                            -25.0205078125,
                            -106.5107421875
                        ],
                        [
                            -24.0205078125,
                            8.4892578125
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_350",
            "properties": {
                "name": "Youth Union",
                "description": "the working offices of Youth union related to university indoor and outdoor activities"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -673.0205078125,
                            9.4892578125
                        ],
                        [
                            -400.0205078125,
                            9.4892578125
                        ],
                        [
                            -399.0205078125,
                            -111.5107421875
                        ],
                        [
                            -672.0205078125,
                            -111.5107421875
                        ],
                        [
                            -673.0205078125,
                            9.4892578125
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_372",
            "properties": {
                "name": "Stair_1",
                "description": "Ground stair"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -885.0205078125,
                            -115.5107421875
                        ],
                        [
                            -823.0205078125,
                            -115.5107421875
                        ],
                        [
                            -823.0205078125,
                            -188.5107421875
                        ],
                        [
                            -885.0205078125,
                            -188.5107421875
                        ],
                        [
                            -885.0205078125,
                            -115.5107421875
                        ]
                    ]
                ]
            }
        }
    ]
}
geojson = new OpenLayers.Format.GeoJSON();
vectors = new OpenLayers.Layer.Vector();
selectControl= new OpenLayers.Control.SelectFeature(vectors,
    {onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
map.addLayer(vectors);
vectors.addFeatures(geojson.read(featurecollection));
map.addControl(selectControl);
selectControl.activate();
function onPopupClose(){selectControl.unselect(selectedFeature);};
function onFeatureSelect(feature){
    selectedFeature = feature;
    popup = new OpenLayers.Popup.FramedCloud(feature.id + "pop", feature.geometry.getBounds().getCenterLonLat(),null,"<div style='font-size:.8em'>Room: " + feature.attributes.name + "<br />Description: " + feature.attributes.description + "</div>",null, true, onPopupClose);
    feature.popup = popup;
    map.addPopup(popup);
}
function onFeatureUnselect(feature){
    map.removePopup(feature.popup);
    feature.popup.destroy();
    feature.popup = null;
}
